package cn.com.taiji.pos.service.impl;

import cn.com.taiji.pos.entity.CardConsumptionRule;
import cn.com.taiji.pos.entity.CardCustomer;
import cn.com.taiji.pos.entity.ConfigMealTime;
import cn.com.taiji.pos.mapper.CardConsumptionRuleMapper;
import cn.com.taiji.pos.mapper.CardCustomerMapper;
import cn.com.taiji.pos.service.ICardConsumptionRuleService;
import cn.com.taiji.pos.service.IConfigMealTimeService;
import cn.com.taiji.pos.service.ISystemPosMachineService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
@Service
public class CardConsumptionRuleServiceImpl extends ServiceImpl<CardConsumptionRuleMapper, CardConsumptionRule> implements ICardConsumptionRuleService {
    @Autowired
    private CardConsumptionRuleMapper cardConsumptionRuleMapper;
    @Autowired
    private CardCustomerMapper cardCustomerMapper;
    @Autowired
    private ISystemPosMachineService systemPosMachineService;
    @Autowired
    private IConfigMealTimeService configMealTimeService;

    @Override
    public CardConsumptionRule findCustomerRule(String customerId, String canci, String physicalCode) {
        CardCustomer cardCustomer = cardCustomerMapper.selectById(customerId);
        ConfigMealTime configMealTime = configMealTimeService.findByName(canci);
        systemPosMachineService.findByPhysicalCode(physicalCode);
        QueryWrapper<CardConsumptionRule> cardConsumptionRuleWrapper = new QueryWrapper<>();
        cardConsumptionRuleWrapper.eq("CUSTOMER_TYPE_ID", cardCustomer.getCustomerTypeId());
        cardConsumptionRuleWrapper.eq("MEAL_TIME_ID", configMealTime.getId());
        return cardConsumptionRuleMapper.selectOne(cardConsumptionRuleWrapper);
    }
}
